<%--
  Created by IntelliJ IDEA.
  User: Rui
  Date: 2018/9/8
  Time: 9:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    String imgSrc=basePath+"resources/images/noImage.jpg";
    session.setAttribute("imgSrc",imgSrc);
%>
<!DOCTYPE html>
<html style="background-color: #fff;">
<head>
    <%@include file="../../../../resources/inc/head.jsp" %>
    <style>
        .menuContent{
            left: 146px !important;
        }
        .layui-form-label{width: 100px}
        .layui-input-block{margin-left: 130px}
    </style>
</head>
<body>
<div class="layui-form" lay-filter="layuiadmin-form-systemCorn" id="layuiadmin-form-systemCorn" style="padding: 20px;">
    <div class="layui-form-item">
        <label class="layui-form-label">产品图片</label>
        <div class="upload-wrapper upload-div " id="layer-photos">
            <div class="upload-item">
                <div class="layui-input-inline" style="width: 550px;">
                    <expect-x:webUploader required="true" pickerId="icon" isLocal="false" fileList="${productCategory.icon}" width="140"/>
                </div>
            </div>
        </div>
    </div>
        <div class="layui-form-item">
            <input type="hidden" value="${productCategory.id}" name="id">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" value="${productCategory.productCategoryName}" name="productCategoryName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上级分类</label>
        <expect-x:zTree pickerId="productCategoryParentId" initKey="0" server="manager/productCategory/category.html" style="metroStyle" width="230" required="false"
                        defaultVal="${productCategory.productCategoryParentId}:${productCategory.productCategory!=null?productCategory.productCategory.productCategoryName:''}"/>
        <label class="layui-form-mid layui-word-aux" style="margin-left:40px"> *不选择分类默认为顶级分类</label>

    </div>
    <input type="hidden" name="productTypeId" value="-1">

    <div class="layui-form-item">
        <label class="layui-form-label">关键词</label>
        <div class="layui-input-block">
            <input type="text" value="${productCategory.productCategoryKeywords}" name="productCategoryKeywords" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea   placeholder="请输入"  style="resize:none" name="productCategoryDesc" class="layui-textarea">${productCategory.productCategoryDesc}</textarea>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-submit" id="LAY-submit" value="确认">
    </div>
</div>

<%@include file="../../../../resources/inc/footer.jsp" %>
<script>
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['tree','index', 'form', 'upload'], function(){
        var $ = layui.$
            ,form = layui.form
            ,upload = layui.upload ;
    })
    function createSubmit() {

        var layer=layui.layer;
        var submitID = 'LAY-submit';
        layui.form.on('submit('+ submitID +')', function(data){
            var formData = data.field;
            delete formData["productCategoryParentIdTree"];
           /* formData.showInNav=layui.$("#showInNav")[0].checked?1:0;
            formData.isShow=layui.$("#isShow")[0].checked?1:0;*/
            console.log(formData.productCategoryParentId.length)
            if (formData.productCategoryParentId==":"){
                formData.productCategoryParentId=0;
            }
            if(formData.productCategoryParentId.indexOf(':')){
                formData.productCategoryParentId = formData.productCategoryParentId.replace(':', '');
            }
            var id=formData.id
            layer.load(2);
            if(formData.id==""||formData.id==null){
                formData.id = null;
                delete formData["id"];
               $.ajax({
                    url:"<%=basePath%>manager/product/category/create.action",
                    type:"POST",
                    data:formData,
                    dataType:"JSON",
                    success:function (data) {
                        layer.closeAll('loading');
                        data=JSON.parse(data);
                        if(data.success){
                            layer.msg("创建成功,1秒后跳转");
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            },1000);
                        }else{
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            }else{
                $.ajax({
                    url:"<%=basePath%>manager/product/category/update/"+id+".action",
                    type:"POST",
                    data:formData,
                    dataType:"JSON",
                    success:function (data) {
                        data=JSON.parse(data);
                        layer.closeAll('loading');
                        if(data.success){
                            layer.msg("修改成功,1秒后跳转")
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            },1000);
                        }else{
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            }
        })
        $("#"+submitID).trigger('click');
    }
</script>
</body>
</html>
